package com.test.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class MyExceptionHander {
	@Resource
	HttpServletRequest request;
	
	@ExceptionHandler(Exception.class)
	public String allException(Exception e){
		if(e instanceof NullPointerException){
			request.setAttribute("msg", "服务器内部错误");
		}else {
			request.setAttribute("msg", "服务器内部错误~~~");
		}
		return "error";
	}
}
